package de.lazy.gui.components;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EtchedBorder;

public class TabCloseButton extends JPanel implements ActionListener{

	JTabbedPane parent;
	String tabID;
	
	private JButton button;
	
	public TabCloseButton(String title, JTabbedPane parent) {

		setOpaque(false);

		JLabel lblTitle = new JLabel(title);
		add(lblTitle);
		
		button = new JButton("X");
		button.setContentAreaFilled(false);
		button.setFocusPainted(false);
		button.setOpaque(false);
		button.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
		add(button);
	}

	public void addCloseOperation(String tabID){
		this.tabID = tabID;
		button.addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(tabID != null && !tabID.isEmpty()){
			parent.remove(parent.indexOfTab(tabID));
		}
	}

}
